package com.stefan.lession03;

import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class TestWindow {

    public static void main(String[] args) {
        new WindowFrame();
    }
}

class WindowFrame extends Frame{

    public WindowFrame(){
        setBackground(Color.blue);
        setBounds(100,100,300,300);
        setVisible(true);
//        addWindowListener(new MyWindowListener());
        this.addWindowListener(
                // 匿名内部类
                new WindowAdapter() {
                    // 关闭窗口
                    @Override
                    public void windowClosing(WindowEvent e) {
                        System.out.println("windowClosing");
                        System.exit(0);
                    }

                    @Override
                    public void windowActivated(WindowEvent e) {
                        System.out.println("windowActivated");
                    }
                }
        );
    }

//    class MyWindowListener extends WindowAdapter {
//
//        @Override
//        public void windowClosing(WindowEvent e) {
//            setVisible(false);// 隐藏窗口，通过按钮，隐藏当前窗口
//            System.exit(0); // 正常退出
//        }
//    }
}
